import {
  ExecutionContext,
  Injectable,
  UnauthorizedException,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  canActivate(context: ExecutionContext) {
    const request = context.switchToHttp().getRequest();

    const user = request.user;
    //console.log(user);
    /* if (!user) {
      throw new UnauthorizedException('请先登录！');
    } else {

    }*/
    return super.canActivate(context);
    // Add your custom authentication logic here
    // for example, call super.logIn(request) to establish a session.
  }
}
